#!/bin/sh

#show histry data 
#history <stock> <day>

export toyear=`date +%y`
export _tmp=`date +%m`
export tomonth=`echo "$_tmp - 1"|bc`
export today=`date +%d`

export fromyear=`date -d-$2day +%y`
export _tmp=`date -d-$2day +%m`
export frommonth=`echo "$_tmp - 1"|bc`
export fromday=`date -d-$2day +%d`

export YahooQuote=`curl -stderr "http://download.finance.yahoo.com/d/quotes.csv?s=$1&f=spol1p2wmryva2cn"`
export AvgVolume=`echo $YahooQuote|cut -d, -f11 | sed 's/N\/A//g'`

curl -stderr "http://finance.yahoo.com/q/hp?s=$1&a=$frommonth&b=$fromday&c=$fromyear&d=$tomonth&e=$today&f=$toyear&g=d" |sed 's/tr/\n/g' |egrep -o "[0-9]+-[A-Za-z]+-[0-9]+|[0-9]+.[0-9]+</td></|>[0-9,]+<"  |tr '<\n' ' '|sed 's/td/\n/g' |sed -e 's/>//g' -e 's/\///g' | sed 's/,//g'| awk '{print $1" "$3" "$2}' > tmpquote

cat tmpquote |head -n `echo $2-3|bc` |while read line
do
    echo $line $AvgVolume |awk '{print $1" "$2" "$3/$4}'
done



